<template>
	<view>
		<RichTextEditor v-model="WatchValue" :init="editorConfig" />
	</view>
</template>

<script>
	import axios from 'axios';
	import Editor from '../tinymce/tinymce-vue'
	export default {
		props: {
			value: String
		},
		components: {
			'RichTextEditor': Editor
		},
		data() {
			return {

				WatchValue: this.value,
				editorConfig: {
					height: 500,
					relative_urls: false,
					convert_urls: false,
					plugins: [
						'advlist image autolink lists link  charmap print preview anchor',
						'searchreplace visualblocks code fullscreen',
						'insertdatetime media table paste code wordcount',
						'autosave  codesample directionality emoticons  hr nonbreaking pagebreak save tabfocus template toc visualchars'
					],
					toolbar: ['undo redo | formatselect | bold italic underline forecolor backcolor hr | \
						alignleft aligncenter alignright alignjustify | \
						bullist numlist outdent indent | lists image media | removeformat fullscreen',
						'restoredraft charmap codesample | ltr rtl | emoticons fullpage insertdatetime |\
						link nonbreaking pagebreak paste | preview print | save searchreplace template | toc visualblocks visualchars | wordcount',
						'table tabledelete | tableprops tablerowprops tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol'
					],
					language: 'zh_CN',
					branding: false,
					draggable_modal: true,
					images_upload_handler: async (blobInfo, success, error) => {

						let files = blobInfo.blob();
					
						// let filename = files.name;
						// 使用 axios 上传，实际开发这段建议写在 api 中再调用 api
						let param = new FormData();

						param.append('file', files, files.name);
					
						let config = {
							headers: {
								'Access-Control-Allow-Origin': '*',
								'x-oss-callback-Authorization': 'access_token'
							}
						};
                        let resultss = await axios.post(this.$api.upload, param,config);
						console.log(resultss);

						success(resultss.data.data.url);







						// const result = await this.$http.get({
						// 	url: 'https://yjykmaster.admin168.net/door-massage/massage/upload/alyOssSignature',
						// 	data: {
						// 		// merchantId: uni.getStorageSync('merchantId'),

						// 	}
						// });
						// const results = result.data
						// // const results = await userOssSignature();
						// const files = blobInfo.blob();
						// console.log(files)
						// // let files = files.raw;
						// let filename = files.name;
						// let markIndex = filename.lastIndexOf('.');
						// let suffix = filename.substring(markIndex);
						// let date = new Date().getTime();
						// // // 构建请求参数
						// let param = new FormData();
						// param.append('key', date + suffix);
						// param.append('policy', results.policy);
						// param.append('OSSAccessKeyId', results.accessId);
						// param.append('success_action_status', '200');

						// param.append('signature', results.signature);
						// param.append('file', files, files.name);
						// param.append('success_action_status', '200');
						// let config = {
						// 	headers: {
						// 		'Access-Control-Allow-Origin': '*',
						// 		'x-oss-callback-Authorization': 'access_token'
						// 	}
						// };
						// console.log('suffix', suffix);
						// console.log(results.host, param, config)
						// let resultss = await axios.post(results.host, param, config);
						// let url = results.host + '/' + date + suffix;
						// console.log(url);


						// success(url)




					}
				}
			};
		},
		watch: {
			WatchValue(value) {
				console.log(value)
				this.$emit('change', value)
			}
		}
	}
</script>

<style>

</style>